<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp();
    const CommonChild = {
      template: `
        <div>
          <h3>这是子组件</h3>  
        </div>
      `,
      data() {
        return {
          msg: '这是子组件数据'
        }
      },
      methods: {
        fn(){
          console.log('zzzz');
        }
      }
    }
    const CommonHead = {
      template: `
        <div>
          <h2>父组件</h2>  
          <button ref="btn">按钮</button>
          <hr/>
          <common-child ref="child"></common-child>
        </div>
      `,
     
      mounted(){
        // 会在组件初始化时 编译template完成时触发（template编译成虚拟dom 渲染成真实dom）
        // console.log(this.$refs.btn);
        // console.log(this.$refs.child.msg);
      },
      components: {
        CommonChild
      }
    }
    app.component('CommonHead', CommonHead);
    app.mount('#app')
  </script>
</body>
</html>